package GitWork;

import java.util.Scanner;
public class PasswordManagementSystem {
	String password;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		System.out.println("====================================");
		System.out.println("         欢迎使用密码管理系统         ");
		System.out.println("====================================");
		int x = 0;
		while(x!=5) {
		System.out.println("             请选择操作：             ");
		System.out.println("        1.加密");
		System.out.println("        2.解密");
		System.out.println("        3.判断密码强度");
		System.out.println("        4.密码生成");
		System.out.println("        5.退出");
		System.out.print("请输入选项序号：");
		x=sc.nextInt();
		System.out.println("====================================");
		System.out.println("         欢迎使用密码管理系统         ");
		System.out.println("====================================");
		PasswordManagementSystem pw=new PasswordManagementSystem();
			switch(x) {
			case 1:
				System.out.println("请输入要加密的数字密码：");
				pw.password=sc.next();
				System.out.println("加密后的结果是："+pw.decryption());
				System.out.println("按任意键返回");
				break;
			case 2:
				System.out.println("请输入要解密的数字密码：");
				pw.password=sc.next();
				System.out.println("解密后的结果是："+pw.decryption());
				System.out.println("按任意键返回");
				break;
			}
		}
		sc.close();
	}
	//加密
	String encryption() {
		char[] pw = password.toCharArray();
		for(int i=0;i<pw.length;i++) {
			pw[i]=(char) (pw[i]+(i+1)+3);
			}
		char x=pw[0];
		pw[0]=pw[pw.length-1];
		pw[pw.length-1]=x;
		char pwpro[]=new char[pw.length];
		int j=pw.length-1;
		for(int i=0;i<pwpro.length;i++) {
			pwpro[i]=pw[j];
			j--;
		}
		String newpw=new String(pwpro);
		return newpw;
	}
	//解密
	String decryption() {
		char[] pw = password.toCharArray();
		char pwpro[]=new char[pw.length];
		int j=pwpro.length-1;
		for(int i=0;i<pwpro.length;i++) {
			pwpro[i]=pw[j];
			j--;
		}
		char x=pwpro[0];
		pwpro[0]=pwpro[pwpro.length-1];
		pwpro[pwpro.length-1]=x;
		for(int i=0;i<pwpro.length;i++) {
			pwpro[i]=(char) (pwpro[i]-(i+1)-3);
			}
		String newpw=new String(pwpro);
		return newpw;
	}
	//判断密码强度
}